package cn.ubeta.b2c.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.ubeta.b2c.R;
import cn.ubeta.b2c.utils.DensityUtil;

/**
 * Created by denny on 2016/11/8.
 */

public class RecvDateView extends RelativeLayout {

    private ListView mListView;
    private TextView mTvTime1;
    private TextView mTvTime2;
    private TextView mTvTime3;

    public RecvDateView(Context context) {
        this(context, null);
    }

    public RecvDateView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RecvDateView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        LayoutInflater.from(context).inflate(R.layout.widget_recv_date, this);
        init(attrs);
    }

    /**
     * 初始化
     * @param attrs
     */
    private void init(AttributeSet attrs) {
        mListView = (ListView) findViewById(R.id.lv_date);
        mTvTime1 = (TextView) findViewById(R.id.tv_time1);
        mTvTime2 = (TextView) findViewById(R.id.tv_time2);
        mTvTime3 = (TextView) findViewById(R.id.tv_time3);

        mListView.setAdapter(new DateAdapter());
        //mListView.setSelection(1);
        mListView.setItemChecked(1, true);
    }

    class DateAdapter extends BaseAdapter {

        private int selectedPos;

        @Override
        public int getCount() {
            return 7;
        }

        @Override
        public Integer getItem(int i) {
            return i;
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int pos, View view, ViewGroup viewGroup) {
            if (view == null) {
                TextView tv = new TextView(viewGroup.getContext());
                tv.setText("" + pos);
                int dp4 = DensityUtil.dip2px(viewGroup.getContext(), 4);
                tv.setPadding(dp4 * 2, dp4, dp4 * 2, dp4);
                view = tv;
                //view.setBackgroundResource(R.drawable.bg_date_dark);
            }
            return view;
        }
    }
}
